﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Cards;
using System.Collections.ObjectModel;

namespace TexasHoldem.Hands
{
    public abstract class HandBase : IComparable<HandBase>
    {
        protected Card[] orderedCards;

        public abstract HandType HandType { get; }
        public ReadOnlyCollection<Card> OrderedCards { get{return new ReadOnlyCollection<Card>(this.orderedCards);}}

        protected virtual int CompareByRank(HandBase other)
        {
            for (int i = 0; i < 5; i++)
            {
                int result = this.orderedCards[i].Rank.CompareTo(other.orderedCards[i].Rank);
                if (result != 0)
                {
                    return result;
                }
            }
            return 0;
        }

        public HandBase(Card[] orderedCards)
        {
            this.orderedCards = orderedCards;
        }

        public int CompareTo(HandBase other)
        {
            int result = this.HandType.CompareTo(other.HandType);
            if (result != 0)
            {
                return result;
            }
            else
            {
                if (this.GetType() != other.GetType())
                {
                    throw new ArgumentException("other", "Invalid type for comparison.");
                }

                return this.CompareByRank(other);
            }
        }

        public override string ToString()
        {
            return this.HandType.ToString();
        }
    }
}